﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BAITAPNGAY13_5
{
    class HOADONDAL
    {
        public HOADONDAL() {
        } 
         public void ThemHoaDon(string sohd, string mahang, double soluong, double dongia, double trigia, double khuyenmai, string diengiai)
        {
          SqlConnection conn = new SqlConnection();
            conn.ConnectionString = @"Data Source=QUYNHUYEN\SQLEXPRESS;Initial Catalog=QLVT; User Id=sa; Password=sa";
            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into hoadon values ('" + sohd + "','" + mahang + "'," + soluong.ToString() + "," + dongia.ToString() + "," + trigia.ToString() + "," + khuyenmai.ToString() + ",'" + diengiai + "')", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
         public DataTable DOCDANHSACHHoaDon()
         {
             SqlConnection conn = new SqlConnection();
             conn.ConnectionString = @"Data Source=QUYNHUYEN\SQLEXPRESS;Initial Catalog=QLVT; User Id=sa; Password=sa";
             conn.Open();
             SqlCommand cmd = new SqlCommand("SELECT * FROM HOADON inner join hanghoa on HOADON.mahang=HANGHOA.mahang" , conn);
             SqlDataReader dr = cmd.ExecuteReader();
             DataTable dt = new DataTable();
             dt.Load(dr);
             return dt;
             
    }
         public void XOAHOADON(string sohd)
         {
             SqlConnection conn = new SqlConnection();
             conn.ConnectionString = @"Data Source=QUYNHUYEN\SQLEXPRESS;Initial Catalog=QLVT; User Id=sa; Password=sa";
             conn.Open();
             SqlCommand cmd = new SqlCommand("DELETE FROM HOADON  WHERE sohd='"+ sohd +"'", conn);
             cmd.ExecuteNonQuery();
             conn.Close();
         }



    }
}
